package day20171229;

import java.io.*;
import java.util.HashMap;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * Created by JAVA on 2017/12/29.
 */
public class Test {
    public static void main(String[] args) {
        //期末大作业
        Map<String,Integer>map=new HashMap<String,Integer>();
        BufferedReader reader=null;
            try {
                reader = new BufferedReader(new FileReader("F:\\names.txt"));
                String sno = null;

                //读取学生的学号，并存入map集合
                while ((sno = reader.readLine()) != null){
                    map.put(sno,0);
                }

                File file = new File("F:\\pingshizuoye");

                File[] files = file.listFiles();

                //遍历文件夹下的每一个文件
                //面向对象程序设计Java2016级信本1班1606101024陈来实验二.doccx
                //从字符串提取部分信息：1606101120
                //获取到的学号
                for (File f:files){
                    String fileName=f.getName();

                    Matcher matcher = Pattern.compile(" 信本1班(\\d+)").matcher(fileName);

                    while (matcher.find()){
                        if (map.get(matcher.group(1)) == null){
                            map.put(matcher.group(1),0);
                        } else {
                            map.put(matcher.group(1),1);
                        }
                    }
                }

                for (Map.Entry<String, Integer> entry : map.entrySet()) {

                    if (entry.getValue() == 0){

                        System.out.println("Key = " + entry.getKey() + ", Value = " + entry.getValue());

                    }

                }

            } catch (FileNotFoundException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            } finally {
                try {
                    reader.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }

        }
}
